import Vue from "vue";
import "./plugins/extend";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import Vant from "vant";
import "vant/lib/index.css";
import "./assets/style.css";
import Vuei18n from "vue-i18n";
import { Lazyload, Toast } from "vant";
//引入nprogress
import NProgress from "nprogress"; // 进度条
import "nprogress/nprogress.css"; //这个样式必须引入
// 简单配置
NProgress.inc(0.5);
NProgress.configure({ easing: "ease", speed: 500, showSpinner: false });

Vue.config.productionTip = false;
Vue.use(Vant);
Vue.use(Lazyload, {
  lazyComponent: true,
});

Vue.use(Vuei18n);
const i18n = new Vuei18n({
  locale: localStorage.getItem("siteLang") || "zh-CN",
  //this.$i18n.locale // 通过切换locale的值来实现语言切换
  messages: {
    "zh-CN": require("../public/lang/zh"), // 中文语言包
    "en-US": require("../public/lang/en"), // 英文语言包
  },
});
store.commit("updateLang", i18n.locale);
i18n.name = {
  "zh-CN": "china",
  "en-US": "english",
};
Vue.$defaultFontSize();
window.addEventListener("resize", function() {
  Vue.$defaultFontSize();
});
store.commit("updateToken");
store.commit("openScreenShow", true);
router.beforeEach((to, from, next) => {
  //console.log(to, from);
  NProgress.start();
  store.commit("openScreenShow", true);
  /* if (!store.state.isLogin && !/REGISTER|LOGIN|FORGOTPASSWORD/.test(to.name)) {
    next({
      name: "LOGIN",
      params: { bounce: encodeURIComponent(to.path) },
    });
  } else { */
  next();
  //}
});
router.afterEach((to) => {
  NProgress.done();
  store.commit("openScreenShow", false);
});
let vueObj = new Vue({
  router,
  store,
  i18n,
  render: (h) => h(App),
}).$mount("#app");
